﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Algobox.JuicyLib.Apps.Liquid;

namespace CanadianTradeImporter
{
    class Program
    {
        // default connection string
        // Data Source=localhost;Initial Catalog=LiquidView;Integrated Security=True

        // local connection string over VPN
        // Data Source=liqsql01b;Initial Catalog=LiquidView;User ID=beic;Password=blah

        static void Main(string[] args)
        {

            if (args.Length != 2)
            {
                Console.WriteLine(CONSOLE);
            }

            string filename = String.Empty;
            DateTime fileDate = DateTime.MinValue;

            foreach (string arg in args)
            {
                if (arg.IndexOf(DATE) == 0)
                {
                    if (!DateTime.TryParseExact(arg.Substring(DATE.Length), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out fileDate))
                    {
                        Console.WriteLine(CONSOLE);
                        return;
                    }
                }
                else if (arg.IndexOf(FILE) == 0)
                {
                    filename = arg.Substring(FILE.Length);
                }
                else
                {
                    Console.WriteLine(CONSOLE);
                    return;
                }
            }

            if(filename == null || filename == String.Empty || fileDate == DateTime.MinValue)
            {
                Console.WriteLine(CONSOLE);
                return;
            }

            CanadianDMAFile cad = new CanadianDMAFile(CanadianTradeImporter.Properties.Settings.Default.DBConString);
            cad.ImportStockFile(filename, fileDate, CanadianTradeImporter.Properties.Settings.Default.SkipRows);
        }

        const string DATE = "-DATE=";
        const string FILE = "-FILE=";
        const string CONSOLE = "Command line switches: -FILE=filename.csv -DATE=yyyyMMdd";
    }
}
